<template>
	<!-- 餘額 -->
	<view class="container">
		<view class="balance_box">
			<view class="head_sculpture">
				<image :src="baseImage(userInfo.avatar)" mode=""></image>
			</view>
			<view style="font-size: 30rpx;margin-bottom: 14rpx;">總額（元）</view>
			<view style="font-size: 36rpx;color: #FA533D;font-weight: bold;">{{userInfo.balance}}</view>
			<view class="consumption_details" @tap="consumption_details">消費明細</view>
		</view>
		<!-- 		<view class="recharge">
			<view class="">去充值</view>
			<image src="/static/images/xiangyoujiantou.png"></image>
		</view> -->

		<scroll-view v-if="storeBalance.length" scroll-y="true" class="scroll_y" @scrolltolower="scroll">
			<view class="shop_balance" @tap="stored_value(item)" v-for="item in storeBalance" :key="item.id">
				<view class="">{{item.store_name}}</view>
				<view class="">
					<text>餘額：</text>
					<text style="color: #FA533D;">{{item.balance}}</text>
				</view>
				<view class="go">
					<text style="margin-right: 10rpx;">去儲值</text>
					<u-icon name="arrow-right"></u-icon>
				</view>
			</view>
			<view v-if="!flag" style="text-align: center;margin: 30rpx;">到底啦~</view>
		</scroll-view>
		<view v-else style="text-align: center;margin: 30rpx;">暫無數據</view>

	</view>
</template>

<script>
	import store from '@/store/index.js'
	import baseURL from '@/utils/baseURL.js'
	import {
		getUserInfo,
		getUserStoreBalance
	} from '@/api/me.js'

	export default {
		data() {
			return {
				page: 1,
				userInfo: '',
				storeBalance: [],
				flag: true
			};
		},
		methods: {
			consumption_details: function() {
				uni.navigateTo({
					url: "/pages/consumption_details/consumption_details"
				})
			},
			scroll() {
				if (this.flag) {
					getUserStoreBalance({
						page: ++this.page
					}).then(res => {
						// console.log(res.data,"店鋪餘額列表")
						if (res.data.length) {
							this.storeBalance = this.storeBalance.concat(res.data)
						} else {
							this.flag = false
						}
					})
				}
			},
			baseImage(url) {
				return baseURL + url
			},
			stored_value(item){
				this.$store.commit('updateStoreDetails',{id:item.store_id})
				uni.navigateTo({
					url:"/pages/stored_value/stored_value"
				})
			}
		},
		onShow() {
			getUserInfo().then(res => {
				// console.log(res.data,"用戶信息")
				this.userInfo = res.data
			})

			getUserStoreBalance({
				page: 1
			}).then(res => {
				// console.log(res.data,"店鋪餘額列表")
				this.storeBalance = res.data
			})
		}
	}
</script>

<style lang="less">
	.container {
		height: calc(100vh - 90rpx);
		background: #F3F5F9;
		padding: 30rpx;
		box-sizing: border-box;

		.balance_box {
			height: 274rpx;
			background: #fff;
			border-radius: 16rpx;
			padding-top: 28rpx;
			box-sizing: border-box;
			text-align: center;
			position: relative;

			.head_sculpture {
				width: 80rpx;
				height: 80rpx;
				border-radius: 50%;
				background: skyblue;
				margin: 0 auto;
				margin-bottom: 22rpx;

				image {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
				}
			}

			.consumption_details {
				font-size: 24rpx;
				position: absolute;
				right: 16rpx;
				top: 12rpx;
			}
		}

		.recharge {
			background: #fff;
			height: 64rpx;
			border-radius: 16rpx;
			margin-top: 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			view {
				font-size: 28rpx;
				margin-left: 12rpx;
			}

			image {
				width: 42rpx;
				height: 37rpx;
				margin-right: 12rpx;
			}
		}

		.scroll_y {
			margin-top: 30rpx;
			height: 65vh;

			// background-color: skyblue;
			.shop_balance {
				width: 690rpx;
				height: 113rpx;
				background: #F8FDFB;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				opacity: 1;
				padding: 0 16rpx;
				box-sizing: border-box;
				color: #000;
				font-size: 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				background-color: #fff;
				.go{
					display: flex;
					align-items: center;
					font-size: 24rpx;
					color: #999;
				}
			}
		}
	}
</style>